package com.example.dragon.adpter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.dragon.bean.OrderBean;
import com.example.dragon.bean.ProblemBean;
import com.example.dragon.dialog.MessageDialog;
import com.example.dragon.dialog.WaitDialog;
import com.example.dragon.untis.CircleImageView;
import com.example.dragon.xmf.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Dragon on 2017/6/24.
 */

public class ProblemAdpter extends RecyclerView.Adapter {

    private List<ProblemBean> problemBeanList = new ArrayList<>();
    Context mcontext;
    boolean falg=true;
    public ProblemAdpter(Context mcontext, List<ProblemBean> problemBeanList) {
        this.mcontext = mcontext;
        this.problemBeanList=problemBeanList;
    }

    public interface OnItemClickLitener {
        void onItemClick(View view, int position);

        void onItemLongClick(View view, int position);
    }

    private PdDriverAdpter.OnItemClickLitener mOnItemClickLitener;

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(mcontext).inflate(R.layout.problem_layout, parent, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        final ProblemBean item = problemBeanList.get(position);

        final ViewHolder viewHolder = (ViewHolder) holder;
        if (item != null) {
            viewHolder.title.setText(item.getHelp_id()+"、"+item.getTitle());
            viewHolder.content.setText(item.getContent());
            viewHolder.trelat.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (falg){
                        viewHolder.clinear.setVisibility(View.VISIBLE);
                        falg = false;
                    }else {
                        viewHolder.clinear.setVisibility(View.GONE);
                        falg =true;
                    }
                }
            });




            if (mOnItemClickLitener != null) {
                holder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        int pos = viewHolder.getLayoutPosition();
                        mOnItemClickLitener.onItemClick(viewHolder.itemView, pos);
                    }
                });

                holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
                    @Override
                    public boolean onLongClick(View v) {
                        int pos = viewHolder.getLayoutPosition();
                        mOnItemClickLitener.onItemLongClick(viewHolder.itemView, pos);
                        return false;
                    }
                });
            }        }
    }
    @Override
    public int getItemCount() {
        return problemBeanList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView title,content;
        RelativeLayout trelat;
        LinearLayout clinear;
        public ViewHolder(View itemView) {
            super(itemView);
            title = (TextView)itemView.findViewById(R.id.proTitleText);
            content = (TextView) itemView.findViewById(R.id.procontentText);
            trelat = (RelativeLayout)itemView.findViewById(R.id.titleRe);
            clinear = (LinearLayout)itemView.findViewById(R.id.contentLin);
        }
    }
}
